//
//  HJInformationModel.m
//  KaiChat
//
//  Created by lx on 2024/3/11.
//

#import "HJInformationModel.h"

@implementation HJInformationModel

MJLogAllIvars

+ (HJInformationModel *)modelWithDict:(NSDictionary *)dict {
    HJInformationModel *model = [[HJInformationModel alloc] init];
    model.userId = toString(dict[@"user_id"]);
    model.nickname = dict[@"nickname"];
    model.avatar = dict[@"avatar"];
    if (toString(dict[@"publish_time"]).length > 10) {
        model.publishTimestamp = [dict[@"publish_time"] integerValue] / 1000;
    } else {
        model.publishTimestamp = [dict[@"publish_time"] integerValue];
    }
    model.informationId = toString(dict[@"id"]);
    
    model.postTitle = [dict[@"post_title"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    model.newsTitle = [dict[@"news_title"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    model.content = dict[@"content"];
    model.source = dict[@"source"];
    model.comment = [dict[@"comment"] integerValue];
    model.like = [dict[@"like"] integerValue];
    model.share = [dict[@"share"] integerValue];
    model.views = [dict[@"views"] integerValue];
    model.type = [dict[@"type"] intValue];
    model.isSelf = [dict[@"is_own"] boolValue];
    model.is_like = [dict[@"is_like"] boolValue];
    model.is_follow = [dict[@"is_follow"] boolValue];

    NSMutableArray *canShowImages = [NSMutableArray array];
    for (NSString *value in dict[@"images"]) {
        if (![value.pathExtension.lowercaseString isEqualToString:@"gif"]) {
            [canShowImages addObject:value];
        }
    }
    model.images = canShowImages;
    model.videos = dict[@"videos"];
    return model;
}

@end
